Public Class frmAltaAlumnos

    Dim string_conexion As String
    Enum estado
        insertar
        modificar
    End Enum
    Enum termino
        aprobado
        rechazado
    End Enum
    Dim accion As estado = estado.insertar

    Private Sub acceso_datos_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.string_conexion = "Data Source=maktub; Initial Catalog=tp4; User Id=sa; Password=mistletoe77;"

    End Sub
    Private Sub carga_combo(ByRef combo As ComboBox, ByRef datos As Data.DataTable, ByVal pk As String, ByVal descripcion As String)
        combo.Items.Clear()
        combo.DataSource = datos
        combo.ValueMember = pk
        combo.DisplayMember = descripcion
    End Sub
    Private Function leo_tabla(ByVal nombre_tabla As String) As Data.DataTable
        Dim conexion As New Data
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNuevo.Click
        enable_buttons(True)
        txtApellido.Focus()
    End Sub


    Private Sub enable_buttons(ByVal bandera As System.Boolean)
        cmdGrabar.Enabled = bandera
        cmdCancelar.Enabled = bandera
        cmdBuscar.Enabled = bandera
        lblApellido.Enabled = bandera
        txtApellido.Enabled = bandera
        lblNombre.Enabled = bandera
        txtNombre.Enabled = bandera
        lblFechaNac.Enabled = bandera
        txtFecha.Enabled = bandera
        rbFem.Enabled = bandera
        rbMasc.Enabled = bandera
        lblTipoDoc.Enabled = bandera
        cbTipoDoc.Enabled = bandera
        lblDoc.Enabled = bandera
        txtDoc.Enabled = bandera
        lblCalle.Enabled = bandera
        txtCalle.Enabled = bandera
        lblNumero.Enabled = bandera
        txtNumero.Enabled = bandera
        ckActiv.Enabled = bandera
        ckCasado.Enabled = bandera
        ckHijos.Enabled = bandera
        lblCarrera.Enabled = bandera
        cbCarrera.Enabled = bandera
    End Sub

    Private Function validar() As Boolean
        If Me.txtApellido.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtApellido.Focus()
            Return False
        End If
        If Me.txtNombre.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtNombre.Focus()
            Return False
        End If
        If Me.txtFecha.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtFecha.Focus()
            Return False
        End If
        If Me.rbFem.Checked = False And Me.rbMasc.Checked = False Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            rbFem.Focus()
            Return False
        End If
        If Me.txtDoc.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtDoc.Focus()
            Return False
        End If
        If Me.txtCalle.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtCalle.Focus()
            Return False
        End If
        If Me.txtNumero.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtNumero.Focus()
            Return False
        End If
        If Me.ckHijos.CheckState = CheckState.Checked And txtCant.Text = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            txtCant.Focus()
            Return False
        End If
        If Me.cbTipoDoc.SelectedText = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            cbTipoDoc.Focus()
            Return False
        End If
        If Me.cbCarrera.SelectedText = "" Then
            MsgBox("Debe completar todos los campos", MsgBoxStyle.Critical, "Importante")
            cbCarrera.Focus()
            Return False
        End If
        Return True

    End Function

    Private Sub txtFecha_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFecha.Validated
        If IsDate(sender.text) Then
            If Not sender.text = Format(CDate(sender.text), "dd/mm/yyyy") Then
            Else
                MsgBox("Fecha Invalida", vbOKOnly + vbCritical, "Atencion")
                sender.Focus()
                Exit Sub
            End If
        Else
            MsgBox("Fecha invalida", vbOKOnly + vbCritical, "Atencion")
            sender.focus()
            Exit Sub
        End If
    End Sub

    Private Sub MaskedTextBox1_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDoc.KeyPress
        validar_numero(e)
    End Sub

    Private Sub validar_numero(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Select Case Asc(e.KeyChar)
            Case 4, 24, 8, 19, 127, 13, 9, 15, 14
                Exit Sub
        End Select

        If IsNumeric(e.KeyChar) = False Then
            MsgBox("Este caracter no es un numero ( " + e.KeyChar + " ) ", vbCritical, "Importante")
            e.KeyChar = ""
        End If
    End Sub

    Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
        Me.Close()
    End Sub

    Private Sub frmAltaAlumnos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub ckHijos_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ckHijos.CheckedChanged
        txtCant.Enabled = ckHijos.CheckState()
        lblCant.Enabled = ckHijos.CheckState()
    End Sub

    Private Sub cmdGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGrabar.Click
        If Me.validar() = True Then

        End If
    End Sub

    Private Sub txtNumero_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumero.KeyPress
        validar_numero(e)
    End Sub

    Private Sub txtCant_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCant.KeyPress
        validar_numero(e)
    End Sub
End Class
